package cn.com.blueInfo.bpm.number.controller;

import cn.com.blueInfo.bpm.common.controller.BaseController;
import cn.com.blueInfo.bpm.common.validation.Create;
import cn.com.blueInfo.bpm.common.validation.Update;
import cn.com.blueInfo.bpm.common.validation.UpdatePartial;
import cn.com.blueInfo.bpm.number.request.NumberSerialDTO;
import cn.com.blueInfo.bpm.number.response.NumberSerialVO;
import cn.com.blueInfo.bpm.number.service.NumberSerialService;
import cn.com.blueInfo.utils.result.ResultInfo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.groups.Default;
import java.util.List;

/**
 * 编号规则流水号表 前端控制器
 * @author suxch
 * @since 2025-08-24 01:39:05
 */
@Tag(name = "编号规则流水号 接口")
@RestController
@RequestMapping("/number/numberSerial")
public class NumberSerialController extends BaseController {

    @Autowired
    private NumberSerialService numberSerialService;

    /**
     * 新建编号规则流水号
     * @param numberSerialDTO 编号规则流水号参数
     * @return ResultInfo
     */
    @Operation(summary = "新增编号规则流水号")
    @PostMapping("/addInfo")
    public ResultInfo<Integer> createNumberSerial(
            @Validated({Create.class, Default.class}) @RequestBody NumberSerialDTO numberSerialDTO) {
        return numberSerialService.addNumberSerial(numberSerialDTO);
    }

    /**
     * 新建编号规则流水号
     * @param numberSerialDTOList 编号规则流水号参数
     * @return ResultInfo
     */
    @Operation(summary = "新增编号规则流水号")
    @PostMapping("/addInfoList")
    public ResultInfo<Integer> batchCreateNumberSerial(
            @Validated({Create.class, Default.class}) @RequestBody List<NumberSerialDTO> numberSerialDTOList) {
        return numberSerialService.batchAddNumberSerial(numberSerialDTOList);
    }

    /**
     * 根据ID删除编号规则流水号
     * @param numberSerialId 编号规则流水号ID
     * @return ResultInfo
     */
    @Operation(summary = "根据ID删除编号规则流水号")
    @DeleteMapping("/removeInfo/{numberSerialId}")
    public ResultInfo<Integer> deleteNumberSerialById(
            @Parameter(name = "ID") @PathVariable Long numberSerialId) {
        return numberSerialService.removeNumberSerial(numberSerialId);
    }

    /**
     * 根据ID删除编号规则流水号
     * @param numberSerialIdList 编号规则流水号ID
     * @return ResultInfo
     */
    @Operation(summary = "根据ID删除编号规则流水号")
    @DeleteMapping("/removeInfoList/{numberSerialIdList}")
    public ResultInfo<Integer> batchDeleteNumberSerialById(
            @Parameter(name = "ID") @PathVariable List<Long> numberSerialIdList) {
        return numberSerialService.batchRemoveNumberSerial(numberSerialIdList);
    }

    /**
     * 根据ID全量更新编号规则流水号
     * @param numberSerialId  编号规则流水号ID
     * @param numberSerialDTO 编号规则流水号参数
     * @return ResultInfo
     */
    @Operation(summary = "根据ID全量更新编号规则流水号")
    @PutMapping("/modifyInfo/{numberSerialId}")
    public ResultInfo<Integer> updateNumberSerialFull(
            @Parameter(name = "ID") @PathVariable Long numberSerialId,
            @Validated({Update.class, Default.class}) @RequestBody NumberSerialDTO numberSerialDTO) {
        validateUpdateId(numberSerialId, numberSerialDTO.getId());
        return numberSerialService.modifyNumberSerial(numberSerialDTO);
    }

    /**
     * 根据ID部分更新编号规则流水号
     * @param numberSerialId               编号规则流水号ID
     * @param numberSerialUpdatePartialDTO 编号规则流水号参数
     * @return ResultInfo
     */
    @Operation(summary = "根据ID部分更新编号规则流水号")
    @PatchMapping("/modifyPartialInfo/{numberSerialId}")
    public ResultInfo<Integer> updateNumberSerialPartial(
            @Parameter(name = "ID") @PathVariable Long numberSerialId,
            @Validated({UpdatePartial.class, Default.class}) @RequestBody
            NumberSerialDTO.UpdatePartialDTO numberSerialUpdatePartialDTO) {
        validateUpdateId(numberSerialId, numberSerialUpdatePartialDTO.getId());
        return numberSerialService.modifyNumberSerialPartial(numberSerialUpdatePartialDTO);
    }

    /**
     * 根据ID查询编号规则流水号
     * @param numberSerialId 编号规则流水号ID
     * @return ResultInfo
     */
    @Operation(summary = "根据ID查询编号规则流水号")
    @GetMapping("/getInfo/{numberSerialId}")
    public ResultInfo<NumberSerialVO> getNumberSerialById(
            @Parameter(name = "ID") @PathVariable Long numberSerialId) {
        return numberSerialService.queryNumberSerialById(numberSerialId);
    }

    /**
     * 分页查询编号规则流水号
     * @param numberSerialQueryDTO 编号规则流水号参数
     * @return ResultInfo
     */
    @Operation(summary = "分页查询编号规则流水号")
    @GetMapping("/getInfos")
    public ResultInfo<Page<NumberSerialVO>> getNumberSerialPage(
            @Validated NumberSerialDTO.QueryDTO numberSerialQueryDTO) {
        return numberSerialService.queryNumberSerialPage(numberSerialQueryDTO);
    }

    /**
     * 根据条件查询编号规则流水号
     * @param numberSerialQueryDTO 编号规则流水号参数
     * @return ResultInfo
     */
    @Operation(summary = "根据条件查询编号规则流水号")
    @GetMapping("/getInfoList")
    public ResultInfo<List<NumberSerialVO>> getNumberSerialList(
            @Validated NumberSerialDTO.QueryDTO numberSerialQueryDTO) {
        return numberSerialService.queryNumberSerialList(numberSerialQueryDTO);
    }

}
